Ext.namespace("Ext.milan.pagejs.page_orgpubdatamanage");


Ext.milan.pagejs.page_orgpubdatamanage.docLoadBeforeCallBack = function() {
};

Ext.milan.pagejs.page_orgpubdatamanage.docOnReadyCallback = function() 
{
	Ext.milan.pagejs.page_orgpubdatamanage.pdTree = new dhtmlXTreeObject("_pubdata_tree","100%","100%",0);
	var pdTree = Ext.milan.pagejs.page_orgpubdatamanage.pdTree;
	pdTree.setImagePath(Milan.skinType+"images/dhtmlx/tree/csh_bluebooks/");
	pdTree.setDataMode("json");
	pdTree.loadJSON("pubData/tree.do");
	
	pdTree.attachEvent("onXLE",function(){
		var form = $("orgPubDataListFormId");
		$("_pubdata_tree").removeChild($("holdinfo_pubdata"));
		if(form.pubdataID.value == -1){
			var firstId = pdTree.getItemIdByIndex(0,0);
			var firstPdId = pdTree.getUserData(firstId,"id");
			pdTree.selectItem("PD"+firstPdId,true);
			pdTree.openItem("PD"+firstPdId);
		}else{
			pdTree.selectItem("PD"+form.deptID.value,true);
			pdTree.openItem("PD"+form.deptID.value);
		}
	});
	pdTree.attachEvent("onClick", function(treeItemID,previouslyItemID){   
		var form = $("orgPubDataListFormId");
		
		$("pdName").innerHTML = pdTree.getItemText(treeItemID);
		$("parentPdName").innerHTML = pdTree.getItemText(pdTree.getParentId(treeItemID));
		$("pdSortNO").innerHTML = pdTree.getUserData(treeItemID,"sortno");
		
		var tmpID = treeItemID;
		var pdPath = "";
		while (tmpID!="0")
		{
			pdPath = pdTree.getItemText(tmpID)+"-"+pdPath;
			tmpID = pdTree.getParentId(tmpID);
		}
		pdPath = pdPath.substring(0,pdPath.length-1);
		$("pdPath").innerHTML = pdPath;
		form.pubdataID.value= pdTree.getUserData(treeItemID,"id");
		form.pubdataName.value = pdTree.getItemText(treeItemID);
		form.parentPubdataID.value = pdTree.getUserData(pdTree.getParentId(treeItemID),"id");
		form.parentPubdataID1.value = pdTree.getUserData(pdTree.getParentId(treeItemID),"id");
		
			$("btnAdd2").style.display = "";
			$("btnEdit").style.display = "";
		
		if (!pdTree.getParentId(treeItemID) || pdTree.getUserData(pdTree.getParentId(treeItemID),"id")==0)
		{
			$("btnMove").style.display = "none";
		}
		else
		{
			$("btnAdds").style.display = "";
			$("btnMove").style.display = "";
			
		}
	});
};


Ext.milan.pagejs.page_orgpubdatamanage.refreshTree = function(showID)
{
	Ext.milan.pagejs.page_orgpubdatamanage.pdTree.selectItem("PD"+showID,true);

}

Ext.milan.pagejs.page_orgpubdatamanage.updatePubdataInfo = function()
{
}

Ext.milan.pagejs.page_orgpubdatamanage.refreshView = function(deptid, parentid)
{
	var url = "pubdataAction.do?actionType=5&parentdeptid=" + parentid + "&deptid=" + deptid;
	Milan.ajaxutility.updateContentUseAjax("POST", url, "org_pubdata_rightFrame");
}

Ext.milan.pagejs.page_orgpubdatamanage.showAddSameLv = function(deptid)
{
	var form = $("orgPubDataListFormId");
	var pid = form.parentPubdataID1.value;
	if(pid == "undefined"){
		pid = "";
	}
    var url = "pubData/create.do?pid=" + pid;
    win = Milan.commonutils.createModelPop(
    {
        title: "新建同级类别",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.page_orgpubdatamanage.showAddTopLv = function()
{
	var form = $("orgPubdataListFormId");
    var url = "dept/pubdataActiontype6.jsp?actionType=6&parentDeptID=0&deptid=0";
    win = Milan.commonutils.createModelPop(
    {
        title: "新建类别",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.page_orgpubdatamanage.showAddSubLv = function(pubdataid)
{
	var form = $("orgPubDataListFormId");
    var url = "pubData/create.do?pid=" + form.pubdataID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "新建下级类别",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);	
}

Ext.milan.pagejs.page_orgpubdatamanage.showUpdatePage = function()
{
	var form = $("orgPubDataListFormId");
    var url = "pubData/edit.do?id=" + form.pubdataID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "编辑类别信息",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.page_orgpubdatamanage.showCopyPage = function()
{
	var form = $("orgPubdataListFormId");
    var url = "dept/copy.do?&deptid=" + form.deptID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "复制类别",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.page_orgpubdatamanage.showMovePage = function()
{
	var form = $("orgPubDataListFormId");
    var url = "pubData/move.do?id=" + form.pubdataID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "移动类别",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}



Ext.milan.pagejs.page_orgpubdatamanage.deletePubdata = function(name, showid)
{
	var form = $("orgPubDataListFormId");
    new Milan.widget.ConfirmDialog("确认信息", "确认要删除类别[" + name + "]吗?", 
    {
    	confirmCallback : function(){
			Milan.ajaxutility.formSubmit(
            {
                url: "pubData/delete.do",
				params: "id=" + form.pubdataID.value,
				success : function(response, option)
				{
					Ext.milan.pagejs.page_orgpubdatamanage.pdTree.deleteItem("PD"+form.pubdataID.value,true);
				}
            });
		},
		cancelCallback : function(){}
    });
};

Ext.milan.pagejs.page_orgpubdatamanage.validateForm = function(form)
{
	if (form.name.value.trim()=="")
	{
		Milan.commonutils.createDelayNotifyModel("输入提示", "类别名称 不能为空!");
		return false;
	}
	if (form.sortno.value.trim()=="")
	{
		Milan.commonutils.createDelayNotifyModel("输入提示", "类别序号 不能为空!");
		return false;
	}
	if (!Milan.string.isValidText(form.name.value,"!@#$%^&*+|=?';:\"",true)) 
	{
		Milan.commonutils.createDelayNotifyModel("输入提示", "类别名称含有非法字符!");
		return false;
	}
	if(form.name.value.trim().length>30)
	{
	    Milan.commonutils.createDelayNotifyModel("输入提示", "类别名称必须在30个字符以内!");
		return false;
	}
	if (!Milan.string.isNumber(form.sortno.value.trim()))
	{
		Milan.commonutils.createDelayNotifyModel("输入提示", "类别序号有效输入为0~99之间的数字!");
		return false;
	}
	return true;    
}

Ext.milan.pagejs.page_orgpubdatamanage.addPubdata = function(formId)
{
	var form = $(formId);
	if (!Ext.milan.pagejs.page_orgpubdatamanage.validateForm(form))
		return;
	Milan.ajaxutility.formSubmit(
    {
        form: "add_pubData_form",
        success: function(response){
			var XMLDoc = response.responseXML;
			var pubdataID = XMLDoc.getElementsByTagName("param")[0].firstChild.nodeValue;
			var pdTree = Ext.milan.pagejs.page_orgpubdatamanage.pdTree;
			pdTree.insertNewChild("PD"+form.pid.value,"PD"+pubdataID,form.name.value);
			pdTree.setUserData("PD"+pubdataID,"id",pubdataID);
			pdTree.setUserData("PD"+pubdataID,"sortno",form.sortno.value);
			pdTree.selectItem("PD"+pubdataID,true);
			win.closeDialog();
		}
    });
}

Ext.milan.pagejs.page_orgpubdatamanage.updatePubdata = function(formId,parentid)
{
	var form = $(formId);
	if (!Ext.milan.pagejs.page_orgpubdatamanage.validateForm(form))
		return;
	Milan.ajaxutility.formSubmit(
    {
        form: formId,
        success: function(){
			var form = $(formId);
			var pubdataID = form.id.value;
			var pdTree = Ext.milan.pagejs.page_orgpubdatamanage.pdTree;

			pdTree.setItemText("PD"+pubdataID,form.name.value);
			pdTree.setUserData("PD"+pubdataID,"sortno",form.sortno.value);
			pdTree.selectItem("PD"+pubdataID,true);
			
			win.closeDialog();

		}
    });
}


Ext.milan.pagejs.page_orgpubdatamanage.movePubdata = function()
{
	var form = $("move_pubData_form");
	if(form.pid.value == form.id.value)
	{
	    new Milan.widget.Dialog("输入提示", "无法将本类别设为自身的上级类别，请重新选择!");
		return false;
	}
	if(form.pid.value == form.preparentid.value)
	{
	    new Milan.widget.Dialog("输入提示", "移动后的上级类别与原上级类别一样，请重新选择!");
		return false;
	}
	Milan.ajaxutility.formSubmit(
    {
        form: "move_pubData_form",
        success: function(){
			var form = $("move_pubData_form");
			var parentID = form.pid.value;
			var pdTree = Ext.milan.pagejs.page_orgpubdatamanage.pdTree;
			var pubdataID = form.id.value;
			pdTree.moveItem("PD"+pubdataID,"item_child","PD"+parentID);
			pdTree.selectItem("PD"+pubdataID,true);
			
			win.closeDialog();
			
		}
    });
}

Ext.milan.pagejs.page_orgpubdatamanage.clearPubdata = function()
{
	var form = $("clearOrgPubdataFormId");
    new Milan.widget.ComfirmDialog("确认信息", "确认要清空此类别?", 
    {
    	confirmCallback : function(){
			Milan.ajaxutility.formSubmit(
            {
                form : "clearOrgPubdataFormId",
                success: function(){
                	win.closeDialog();
				}
            });
		},
		cancelCallback : function(){}
    });
}

/**
 * 选择类别
 */
Ext.milan.pagejs.page_orgpubdatamanage.selectPubdata = function(formId)
{
	new Milan.widget.Selector({
		orgType:"32",
		title:"类别选择",
		deptUrl:"dept/selectDept.do?",
		quickSelectUrl:"dept/quickSelectDept.do?",
		searchUrl:"dept/selectDeptByDeptid.do?",
		isRecentEnable :false,
		isUpdateRecentEnable :false
	},
	false,
	{
		onSelectedCallBack : function(arr)
		{
	 		if (arr!=null)
	    	{
			    var form = $(formId);
	        	form.parentDeptName.value = arr[0].name;
		        form.parentdeptid.value = arr[0].deptid;
			}
		}
	});
	
}

Ext.milan.pagejs.page_orgpubdatamanage.showTree = function(){
	var url = "pubData/loadTree.do?callbackFunction=Ext.milan.pagejs.page_orgpubdatamanage.selectCtg";
	this.win2 = Milan.commonutils.createModelPop({
		title: "数据字典类别选择",
		url:url,
		height: "300px",
		width : "275px"
	});
};

Ext.milan.pagejs.page_orgpubdatamanage.selectCtg = function(){
	var sel = this.fcSelectionTree.getSelectedItemId();
	if(!sel){
		new Milan.widget.Dialog('提示','必须选择类别');
	}else{
		var selText = this.fcSelectionTree.getSelectedItemText();
		if(this.win2){
			var pdid = this.fcSelectionTree.getUserData(sel,"id");
			$("pid").value = pdid;
			$("parentName").value = selText;
			
			this.win2.closeDialog();
			this.win2 = null;
	    }
		this.fcSelectionTree = null;
	}
};

Ext.milan.pagejs.page_orgpubdatamanage.hideWin = function()
{
	if(win)
	    win.closeDialog()
}
